package com.suxin.thread.manager.threadpool;

import javax.validation.constraints.NotNull;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author Tang
 * @classname NameThreadFactory
 * @description [  ]
 * @date 2022/8/11 16:37
 */
public class NameThreadFactory implements ThreadFactory {

    private static final AtomicInteger ID = new AtomicInteger(1);
    private final String name;

    public NameThreadFactory(String name) {
        this.name = name;
    }

    @Override
    public Thread newThread(@NotNull Runnable runnable) {
        return new Thread(runnable,name + "-" + ID.getAndDecrement());
    }

}
